package com.crx.springbootinit.controller.user;

import com.crx.springbootinit.annotation.LogApiAnno;
import com.crx.springbootinit.common.BaseResponse;
import com.crx.springbootinit.common.ResultUtils;
import com.crx.springbootinit.model.dto.file.UploadFileRequest;
import com.crx.springbootinit.service.IFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * 文件接口
 *

 */
@RestController
@RequestMapping("/user/file")
@Slf4j
@Api(tags = "文件模块接口")
public class FileController {
    @Resource
    private IFileService fileService;

    /**
     * 文件上传
     *
     * @param multipartFile
     * @param uploadFileRequest
     * @return
     */
    @PostMapping("/upload")
    @ApiOperation("上传文件")
    @LogApiAnno(title = "文件上传模块", businessType = "POST")
    public BaseResponse<String> uploadFile(@RequestPart("file") MultipartFile multipartFile,
            UploadFileRequest uploadFileRequest) {
       return ResultUtils.success(fileService.uploadFile(multipartFile,uploadFileRequest));
    }

}
